﻿using System;
using System.Collections.Specialized;
using System.Web.UI.WebControls;
using Telerik.Web.UI;

public partial class ltMan_users_ipList : AdminBasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        SqlPager pager = new SqlPager("lt_iplist", "i_id", "*");
        pager.OrderBy = "i_id desc";
        RadGridBinder.Create(RadGrid1, pager);
    }
    protected void RadGrid1_DeleteCommand(object sender, GridCommandEventArgs e)
    {
        GridCommander.Delete(e, "delete lt_iplist where i_id=@i_id", "i_id");
    }
    protected void b1_Click(object sender, EventArgs e)
    {
        RadGrid1.Rebind();
    }
    protected void RadGrid1_UpdateCommand(object sender, GridCommandEventArgs e)
    {
        HybridDictionary hd = GridCommander.ExtractValues(e);
        string ip = hd["i_ip"].ToString();
        if (!IpHelper.IsIp(ip))
        {
            RadAlertM("ip地址不正确");
            e.Canceled = true;
        }
        IpHelper.Update(ip, byte.Parse(hd["i_type"].ToString()), int.Parse(hd["i_id"].ToString()));
    }
    protected void RadGrid1_InsertCommand(object sender, GridCommandEventArgs e)
    {
        HybridDictionary hd = GridCommander.ExtractValues(e);
        string ip = hd["i_ip"].ToString();
        if (!IpHelper.IsIp(ip))
        {
            RadAlertM("ip地址不正确");
            e.Canceled = true;
        }
        IpHelper.Add(ip, byte.Parse(hd["i_type"].ToString()));
    }
    protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
        {
            RadButton sex = e.Item.FindControl("cSex") as RadButton;
            HiddenField hidden2 = e.Item.FindControl("HiddenField2") as HiddenField;
            sex.SelectedToggleStateIndex = string.IsNullOrEmpty(hidden2.Value) ? 0 : Convert.ToInt32(hidden2.Value);
            sex.OnClientToggleStateChanged = "function(s,e){$('#" + hidden2.ClientID + "').val(s.get_selectedToggleStateIndex());}";
            if (string.IsNullOrEmpty(hidden2.Value))
                hidden2.Value = sex.SelectedToggleStateIndex.ToString();
        }
    }
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
        {
            RadButton sex = e.Item.FindControl("cSex") as RadButton;
            HiddenField hidden2 = e.Item.FindControl("HiddenField2") as HiddenField;
            sex.SelectedToggleStateIndex = string.IsNullOrEmpty(hidden2.Value) ? 0 : Convert.ToInt32(hidden2.Value);
            if (string.IsNullOrEmpty(hidden2.Value))
                hidden2.Value = sex.SelectedToggleStateIndex.ToString();
        }
    }
}